﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;

namespace mscook.mvc.Core
{
    public class Email
    {
        public Email(string StrSmtpServer,string StrFrom, string StrFromPass , string StrSubject, string StrBody, string StrTo)
        {
            this.StrBody = StrBody;
            this.StrFrom = StrFrom;
            this.StrFromPass = StrFromPass;
            this.StrSmtpServer = StrSmtpServer;
            this.StrSubject = StrSubject;
            this.StrTo = StrTo;
        }
        public string StrSmtpServer
        {
            set;
            get;
        }

        public string StrFromPass
        {
            set;
            get;
        }

        public string StrFrom
        {
            set;
            get;
        }

        public string StrSubject
        {
            set;
            get;
        }

        public string StrBody
        {
            set;
            get;
        }

        public string StrTo
        {
            set;
            get;
        }

        public bool Send()
        {
            try
            {
                System.Net.Mail.SmtpClient client = new SmtpClient(StrSmtpServer);
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential(StrFrom,StrFromPass);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;

                System.Net.Mail.MailMessage message = new MailMessage("webmaster@chu.sh", StrTo, StrSubject, StrBody);
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.IsBodyHtml = true;
                client.Send(message);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}